import conf from '@/store/__config'
let store = {}
const isServer = typeof window === 'undefined'
export function initializeStore (initialState) {
  if (isServer) {
    return _initStore(initialState)
  } else {
    if (Object.keys(store).length === 0) {
      store = _initStore(initialState)
    }
    return store
  }
}

function _initStore(initialState = {}) {
  let storeCls = {}
  for (let k in conf) {
    const state = initialState[k] || null
    storeCls[k] = new conf[k](state)
  }
  return storeCls
}
/*
if (process.env.NODE_ENV === 'development') { // 开发模式暂时注释
  const { enableLogging } = require('mobx-logger')
  enableLogging({
    predicate: () => true,
    action: true,
    transaction: true,
    reaction: true,
    compute: true
  })
}
*/
